import {
  Controller,
  Get,
  Body,
  Post,
  Delete,
  Param,
  HttpStatus,
} from '@nestjs/common';
import { BannerService } from '../services/banner.service';
import { CreateBannerDto } from '../dto/create_banner.dto';
import { Public } from '@/modules/core/decorators/publicGuards';
@Controller('banner')
export class BannerController {
  constructor(private bannerService: BannerService) {}
  @Post('create')
  async create(@Body() body: CreateBannerDto) {
    return await this.bannerService.create(body);
  }

  @Get('list')
  @Public()
  async list() {
    return await this.bannerService.list();
  }

  @Delete('delete/:id')
  async delete(@Param('id') id: string) {
    try {
      await this.bannerService.delete(id);
      return {
        statusCode: HttpStatus.OK,
        msg: '删除成功',
      };
    } catch (error) {
      return {
        statusCode: HttpStatus.BAD_REQUEST,
        msg: '删除失败',
      };
    }
  }
  @Post('update/:id')
  async update(@Param('id') id: string, @Body() body: CreateBannerDto) {
    return await this.bannerService.update(id, body);
  }
}
